package com.ruoyi.eqmonitor.smdtv.controller;

import java.io.InputStream;
import java.util.Iterator;
import java.util.List;

import com.ruoyi.common.core.web.page.PageDomain;
import com.ruoyi.common.core.web.page.TableSupport;
import com.ruoyi.eqmonitor.smdtv.domain.Smdtv11;
import com.ruoyi.eqmonitor.smdtv.domain.Smdtv19;
import com.ruoyi.eqmonitor.smdtv.service.ISmdtv19Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;

import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

@Api(tags = "农村终水端")
@RestController
@RequestMapping("/smdtv19")
public class Smdtv19Controller extends BaseController{
    
    @Autowired
    private ISmdtv19Service smdtv19Service;

    /**
     * 查询农村终水端列表
     */
    @GetMapping("/list")
    public TableDataInfo<?> list(Smdtv19 smdtv19){
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        List<Smdtv19> list = smdtv19Service.selectSmdtv19List(smdtv19,(pageNum - 1) * pageSize,pageSize);
        return getDataTable2(list,smdtv19Service.getTotal(smdtv19));
    }

    /**
     * 查询全部农村终水端
     */
    @GetMapping("/all")
    public AjaxResult all(){
        return AjaxResult.success(smdtv19Service.getAll());
    }

    /**
     * 根据id查询农村终水端
     */
    @GetMapping(value = "/{fid}")
    public AjaxResult getInfo(@PathVariable("fid") Long fid){
        return AjaxResult.success(smdtv19Service.selectSmdtv19ByFid(fid));
    }

    /**
     * 新增农村终水端
     */
    @Log(title = "农村终水端", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Smdtv19 smdtv19){
        smdtv19.setCreateTime(new Date());
        return toAjax(smdtv19Service.save(smdtv19));
    }

    /**
     * 修改农村终水端
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Smdtv19 smdtv19){
        return toAjax(smdtv19Service.updateById(smdtv19));
    }

    /**
     * 传入@PathVariable的格式类似为/1,2,3,4,5时,会自动转为数组
     */
    @Log(title = "农村终水端", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fids}")
    public AjaxResult remove(@PathVariable Long[] fids){
        return toAjax(smdtv19Service.removeByIds(Arrays.asList(fids)));
    }
    
    /**
     * 导出农村终水端列表
     */
    @Log(title = "农村终水端", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Smdtv19 smdtv19){
        List<Smdtv19> list = smdtv19Service.selectSmdtv19List(smdtv19,null,null);
        ExcelUtil<Smdtv19> util = new ExcelUtil<Smdtv19>(Smdtv19.class);
        util.exportExcel(response, list, "农村终水端数据");
    }
    
}
